{extend name="index/iframe" /}

{block name="content"}
<form class="layui-form layui-form-my" action="">
    <input type="hidden" value="{$Think.get.id}" name="id">
    <div class="layui-form-item">
        <label class="layui-form-label">返利名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" value="{$find.name}" lay-verify="required" placeholder="请输入返利名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">选择游戏</label>
        <div class="layui-input-block select-box">
            <select class="selectpicker" multiple data-live-search="true" data-style="btn-inverse">
                {volist name="gameNotice" id="vo"}
                <option value="{$vo.game_id}" {in name="$vo.game_id" value="$find.gamelist"}selected{else/}''{/in}>{$vo.game_id}:{$vo.game_name}</option>
                {/volist}
            </select>
            <input type="hidden" name="gamelist" id="gamelist">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">返利日期</label>
        <div class="layui-input-block">
            <input type="text" name="datetime" value="{$find.starttime} - {$find.endtime}" class="layui-input" lay-verify="required" id="datetime" placeholder="yyyy-MM-dd HH:mm:ss - yyyy-MM-dd HH:mm:ss"  lay-verify="datetime" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">返利规则</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入返利规则" name="rule" lay-verify="required" class="layui-textarea">{$find.rule}</textarea>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <select name="type" lay-verify="required">
                <option value="">请选择返利类型</option>
                {foreach $Think.config.rebate_rule as $k=>$v}
                <option value="{$k}" {$find.type==$v ? 'selected' : ''}>{$v}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn my-btn" lay-submit="" lay-filter="submitBtn">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}

{block name="css"}
<link rel="stylesheet" href="__STATIC__/js/bootselect/bootstrap-3.3.4.css">
<link rel="stylesheet" href="__STATIC__/js/bootselect/dist/css/bootstrap-select.css">
{/block}

{block name="js"}
<script src="__STATIC__/js/bootselect/jquery-2.0.3.min.js"></script>
<script src="__STATIC__/js/bootselect/bootstrap-3.3.4.js"></script>
<script src="__STATIC__/js/bootselect/dist/js/bootstrap-select.js"></script>
<script>
    layui.use(['form', 'laydate'], function(){
        var form = layui.form
            ,$ = layui.$
            ,layer = layui.layer
            ,laydate = layui.laydate;

        //多选
        $('.selectpicker').change(function() {
            $('#gamelist').val($(this).val());
        })
        $('#gamelist').val($('.selectpicker').val());
        $('.select-box .layui-form-select').css('display', 'none');

        //日期
        laydate.render({
            elem: '#datetime'
            ,type: 'datetime'
            ,range: true
        });

        //提交
        form.on('submit(submitBtn)', function(data){
            var load = layer.load();
            $.post('{:url("RebateRule/edit")}',data.field, function(json){
                layer.close(load);
                json.code==0 ? layer.msg(json.msg, {icon: 1, time: 1000}) : layer.msg(json.msg, {icon: 0, time: 1000});
            }, 'JSON').error(function(){
                layer.close(load);
                layer.msg('连接超时，请联系后台管理员', {icon: 2, time:3000});
            });
            return false;
        });
    });
</script>
{/block}